import { createBrowserRouter, RouterProvider } from "react-router-dom";
import HomePage from "@pages/home";
import LoginPage from '@pages/login';
import MainLayout from "@shared/mainLayout";
import Question from "@pages/question";
import Video from "@pages/video";
import Mine from "@pages/mine";
import AuthRoute from "@router/authRoute";
import Personal from "@pages/personal";
import Article from "@pages/article";
import Chat from "@pages/chat";
import Search from "@pages/search";
import SearchResult from "@pages/searchResult";
// 合并路由配置
import { Navigate } from "react-router-dom";
// 合并路由配置
export const router = createBrowserRouter([
  {
    path: "/",
    element: <MainLayout />,
    children: [
      {
        path: "",
        element: <Navigate to="/0" />,
      },
      {
        path: ":cid",
        element: <HomePage />,
      },
      {
        path: "question",
        element: <Question />,
      },
      {
        path: "video",
        element: <Video />,
      },
      {
        path: "mine",
        element: (
          <AuthRoute>
            <Mine />
          </AuthRoute>
        ),
      },
    ],
  },
  {
    path: "/login",
    element: <LoginPage />,
  },
  { path: "/article/:id", element: <Article /> },
  {
    path: "/private",
    element: <AuthRoute />,
    children: [
      { path: "chat", element: <Chat /> },
      {
        path: "personal",
        element: <Personal />,
      },
    ],
  },
  {
    path: "/search",
    element: <Search />
  },
  {
    path: "/result/:key",
    element: <SearchResult />
  }
]);

export default function AppRouter() {
  return <RouterProvider router={router} />;
}